/*
 * Copyright 2004 IBM Corporation.  ALL RIGHTS RESERVED.
 *
 * Author: PK
 * Date: 03/12/2004, Version: 1.0, File created.
 */
package com.ibm.crm.tma.adapter.messagelog;

/**
 * A utility class to get full path name of directories and fully qualified name
 * of files.
 */
public class TMADirectoryFinder {

    /**
     * Retrurns full path name of the requested directory.
     *
     * @param theDirType : A string constant. To avoid typos, and to become
     * in-sentive to changes, use the string constants defined in the class
     * TMAConstants.
     * @return : The full path to the directory if pointed to by an appropriate
     * environment variable, null otherwise.
     */
    public static String getDirectoryPath(String theDirType)
    {
        //System.out.println("theDirType = " + theDirType);

        if (theDirType.compareTo(TMAConstants.TMA_DATA_DIR) == 0)
        {
            return System.getProperty(TMAConstants.TMA_DATA_DIR);
        }
        else if (theDirType.compareTo(TMAConstants.TMA_LOG_DIR) == 0)
        {
            return System.getProperty(TMAConstants.TMA_LOG_DIR);
        }
        else if (theDirType.compareTo(TMAConstants.TMA_PROP_DIR) == 0)
        {
            return System.getProperty(TMAConstants.TMA_PROP_DIR);
        }
        else if (theDirType.compareTo(TMAConstants.TMA_OUTPUT_DIR) == 0)
        {
            return System.getProperty(TMAConstants.TMA_OUTPUT_DIR);
        }
        else if (theDirType.compareTo(TMAConstants.TMA_HOME) == 0)
        {
            return System.getProperty(TMAConstants.TMA_HOME);
        }
        else if (theDirType.compareTo(TMAConstants.TMA_HOST_NAME) == 0)
        {
            return System.getProperty(TMAConstants.TMA_HOST_NAME);
        }
        else if (theDirType.compareTo(TMAConstants.TMA_INPUT_DIR) == 0)
        {
            return System.getProperty(TMAConstants.TMA_INPUT_DIR);
        }
        else if (theDirType.compareTo(TMAConstants.TMA_SSH_KEYFILE) == 0)
        {
            System.out.println("System.getProperty(TMAConstants.TMA_SSH_KEYFILE = " + System.getProperty(TMAConstants.TMA_SSH_KEYFILE));
            return System.getProperty(TMAConstants.TMA_SSH_KEYFILE);
        }
        else if (theDirType.compareTo(TMAConstants.TMA_SSH_TRUSTFILE) == 0)
        {
            System.out.println("System.getProperty(TMAConstants.TMA_SSH_TRUSTFILE) = " + System.getProperty(TMAConstants.TMA_SSH_TRUSTFILE));
            return System.getProperty(TMAConstants.TMA_SSH_TRUSTFILE);
        }
        else if (theDirType.compareTo(TMAConstants.TMA_SSH_PASSWORD) == 0)
        {
            System.out.println("System.getProperty(TMAConstants.TMA_SSH_PASSWORD) = " + System.getProperty(TMAConstants.TMA_SSH_PASSWORD));
            return System.getProperty(TMAConstants.TMA_SSH_PASSWORD);
        }

        return null;
    }

    /**
     * Retrurns fully qualified name of a requested file.
     *
     * @param theDirType : A string constant. To avoid typos, and to become
     * in-sentive to changes, use the string constants defined in the class
     * TMAConstants.
     * @param theFileBaseName : The base name of the file.
     * @return : The full name of the given file if pointed to by an appropriate
     * environment variable, null otherwise.
     */
    public static String getFileFullName(
        String theDirType,
        String theFileBaseName) {

        String dirName = null;
        String fileName = null;

        if (theDirType.compareTo(TMAConstants.TMA_DATA_DIR) == 0) {
            dirName = System.getProperty(TMAConstants.TMA_DATA_DIR);
        } else if (theDirType.compareTo(TMAConstants.TMA_LOG_DIR) == 0) {
            dirName = System.getProperty(TMAConstants.TMA_LOG_DIR);
        } else if (theDirType.compareTo(TMAConstants.TMA_PROP_DIR) == 0) {
            dirName = System.getProperty(TMAConstants.TMA_PROP_DIR);
        }

        if (dirName != null) {
            fileName = dirName.concat("/" + theFileBaseName);
        }

        return fileName;
    }
}
